Inserting month as piped text | XM Community
Solved

Inserting month as piped text


Badge +1
I am trying to insert the name of the current month into a question so that it updates automatically. In a verbally-administered survey, the question reads:

> For these statements, please tell me whether the statement was often true, sometimes true, or never true for you in the last 12 months—that is, since last (name of current month).

Essentially, I just want to insert the current month in place of those parentheses. I figure the way to do this is with piped text, but the only date options I am finding that way include the day and year, not just the month name.

Any suggestions on the most efficient way to insert just the current month name?
icon

Best answer by Anonymous 15 August 2018, 23:31

View original

20 replies

Userlevel 7
Badge +27
Add this JavaScript to a question on the page (or the survey header inside a `<script>` tag if you want to use it on multiple pages and questions).
```
Qualtrics.SurveyEngine.addOnload(function() {
var curDate = "${date://CurrentDate/FL}";
jQuery(".monthName").text(curDate.substr(0,curDate.indexOf(" ")));
});
```

Then add this html anywhere you want the name of the current month:
```
<span class="monthName"></span>
```
Hello @smckee ,

Step1: Make a embedded data(month) in survey flow before the question

Step2: Paste the below code in the one previous question (js option) to the required question.

const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];

const d = new Date();
var n=monthNames[d.getMonth()];


Qualtrics.SurveyEngine.setEmbeddedData( 'month', n );

Step3: Now pipe embedded data "month"
Userlevel 7
Badge +27
@Shashi - That won't work with a translated survey.
Hello @smckee ,
If you want that to work in translated survey, follow the steps .!
Badge +1
Thank you, @TomG and @Shashi !

Ended up using TomG's code, since we might end up translating the survey in the future. Works perfectly, as far as I can tell.
Userlevel 6
Badge +5
@TomG, Do you know why I cant get this to work on my end? I have added the javascript to the header, but everytime I try to add the HTML under the source view for the question text it doesn't seem to save.
Userlevel 7
Badge +27
@uhrxx005,

I think have a mistake somewhere. Attached is a working .qsf that you can compare to what you have.
Userlevel 6
Badge +5
@TomG, I got it working. What is happening on both my version and your QSF file is that after it is working, if I go back into the rich content editor for that question the HTML disappears
Userlevel 7
Badge +27
> @uhrxx005 said:
> @TomG, I got it working. What is happening on both my version and your QSF file is that after it is working, if I go back into the rich content editor for that question the HTML disappears

Yes, don't use the Rich Content Editor on questions with HTML. If you have HTML in a question it is best to always edit it in HTML View (even editing in Normal View can sometimes have unintended consequences).
@TomG how can I adjust the code to always show the previous month? Thanks!
Userlevel 7
Badge +27
> @Yasmin said:
> @TomG how can I adjust the code to always show the previous month? Thanks!

Change the date pipe to ${date://OtherDate/FL/-1 month}
Badge +1
In the survey statement/question itself, any idea how I need to alter the piped text to show just the month without the date and year?
Userlevel 7
Badge +27

https://www.qualtrics.com/community/discussion/comment/17910#Comment_17910Replace FL with m (2 digit month). If you don't want a 2-digit month, I don't know any alternatives. Qualtrics used non-standard date formatting that isn't documented anywhere. If there are other month only formats, I don't know what they are (m isn't documented either, I just happen to know about it).

TomG
I'm hoping this is the Easy part: I need to get both the current month and the month after to be available to pipe into the survey. I can currently do the current month with your script in the header, but I can't seem to get a FL/month+1 to work.
Probably the Harder part: If it's possible, I have a question that asks which month someone leaves our company (if it's not the current month as above). It would be useful to pipe a month+1 and a month-1 based on that response into the survey. Is that even possible!
Thanks in advance for any help you can provide.
Geoff.

Userlevel 7
Badge +27

GeoffreyJ ,
Pipe for the next month is ${date://OtherDate/FL/+1 month}
The second part is doable. I would probably use moment.js to parse the input into a date and calculate the other months.

Thanks for your swift comment.
I've got the current month script working, but I can't get it to work with the month+1 script. My current script looks like this:

I've also tried it as two separate scrips



Any advice?

Userlevel 7
Badge +27

You need a space between 1 and month: ${date://OtherDate/FL/+1 month}
Also + isn't a valid character in a class name.

Badge +1

TomG:
Do you happen to know the syntax for displaying only the current four-digit year (the four-digit year for the current date)? I also want to know if it will work if I tell it "-1 year."

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/42205#Comment_42205Current Year:
${date://CurrentDate/Y}
One year ago:
${date://OtherDate/Y/-1 year}

Badge +4

Here is how I did it...
Snag_42c8bda.pngPipe the text into your statements and...
image.pngTada!

Leave a Reply